
//
//  CTSearchBar.m
//  jdforme
//
//  Created by leo on 2017/5/18.
//  Copyright © 2017年 leojingdong.com. All rights reserved.
//
#import "UIView+CTFrame.h"
#import "CTSearchBar.h"

@implementation CTSearchBar

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.font = [UIFont systemFontOfSize:14];
        self.backgroundColor = [UIImage imageNamed:@"searchbar_textfield_background"];
        [self setLeftView];
        [self setRightView];
        
    }
    return self;
}

- (instancetype)init {
    CGFloat width = [UIScreen mainScreen].bounds.size.width - 110;
    CGFloat height = 30;
    CGFloat x = ([UIScreen mainScreen].bounds.size.width - width) * 0.5;
    CGFloat y = 7;
    CGRect frame = CGRectMake(x, y, width, height);
    return [self initWithFrame:frame];
}


- (void)setLeftView {
    UIImageView *leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_search_bar_7_write"]];
    self.leftView = leftImageView;
    self.leftViewMode = UITextFieldViewModeWhileEditing;
    
}
- (void)setRightView {
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setImage:[UIImage imageNamed:@"audio_nav_icon"] forState:UIControlStateNormal];
    [rightButton sizeToFit];
    rightButton.frameWidth += 10;
    rightButton.contentMode = UIViewContentModeCenter;
    self.rightView = rightButton;
    self.rightViewMode = UITextFieldViewModeAlways;
}

@end
